package com.itheima.health.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.health.pojo.OrderSetting;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface OrderSettingMapper extends BaseMapper<OrderSetting> {

    @Select("select orderdate,number,RESERVATIONS  from  t_ordersetting where orderdate between #{beginDate} and #{endDate}")
    List<OrderSetting> findOrderSettingsByOrderDate(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
     @Update("update t_ordersetting set number = #{number} where orderdate =#{orderdate}")
    void updateNumberByOrderDate(@Param("orderdate") String orderdate, @Param("number") int number);

     @Select("select  count(0) from t_ordersetting where  orderdate = #{orderDate} and number > RESERVATIONS")
    int isOrderOkByOrderDate(@Param("orderDate") String orderDate);
     @Update("update t_ordersetting set  RESERVATIONS =RESERVATIONS+1 where ORDERDATE = #{orderDate}")
    void updateReservationsByOrderDate(@Param("orderDate") String orderDate);


    @Delete("DELETE FROM t_ordersetting WHERE ORDERDATE < #{date} ")
    void deleteFile(@Param("date") String date);

    @Update("update t_ordersetting set is_delete=1 where ORDERDATE < #{date}")
    void UpdateIsDatelet(@Param("date") String date);
}
